class Newsletter < ActiveRecord::Base
	validates_presence_of :name, :message
	has_and_belongs_to_many :contacts, :uniq => true
	
	def deliver
		contacts.each do |c|
			email = NewsletterMailer.create_news( c, self )
			email.set_content_type("text/html" )
			NewsletterMailer.deliver( email )
		end
		self[:sent] = true
		self[:sent_at] = Time.now
		self.save!
	end
	
end
